#include <bits/stdc++.h>
using namespace std;
const int N = 30;
int a[N], b[N];

int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    string buf;
    for (int i = 1; i <= n; ++i) {
      cin >> buf;
      char op = buf.back();
      if (op == '1' || op == '2') {
        a[i] = 0;  // ping
      } else {
        a[i] = 1;
      }
    }

    for (int i = 1; i <= n; ++i) {
      cin >> buf;
      char op = buf.back();
      if (op == '1' || op == '2') {
        b[i] = 0;  // ping
      } else {
        b[i] = 1;
      }
    }

    bool ans = true;
    for (int i = 1; i <= n; ++i) {
      if (a[i] + b[i] != 1) {
        ans = false;
        break;
      }
    }
    if (a[n] != 1) ans = false;
    cout << (ans ? "YES\n" : "NO\n");
  }
}
